package com.shelpe.services.simbasync.service.simbaproxy;

import java.util.List;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.shelpe.services.simbasync.dto.InsightWordData;

import lombok.Data;

@FeignClient(name="${simbaproxy.serviceID}", url="${simbaproxy.url}")
@RequestMapping(value = "/simba")
public interface KeywordsProxy {
	
	/**
	 * 根据推广组获取关键词
	 * */
	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.keywordsbyadgroupid.get")
	public String getKeywordsByAdGroupId(@RequestParam("nick") String nick, @RequestParam("adgroup_id") long adgroup_id);
	
	
	
	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.keywords.qscore.split.get")
	public QscoreResponse getKeywordsNewScore(@RequestParam("nick") String nick, @RequestParam("ad_group_id") long adgroup_id, @RequestParam("bidword_ids") String bidword_ids);
	
	/**
	 * 
	 * 根据关键词id获取一组关键词
	 * 
	 * */
	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.keywordsbykeywordids.get")
	public String getKeywordsByKeywordIds(@RequestParam("nick") String nick,@RequestParam("keyword_ids") String keyword_ids);
	
	/***
	 * 
	 * 推广组下的词效果报表数据查询(明细数据不分类型查询)
	 * 
	 * */
	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.rpt.adgroupkeywordeffect.get")
	public String getRptAdgroupKeywordEffect(@RequestParam("subway_token") String subway_token, @RequestParam("nick") String nick, @RequestParam("campaign_id") long campaign_id, @RequestParam("adgroup_id") long adgroup_id, 
			@RequestParam("source") String source, @RequestParam("search_type") String search_type, @RequestParam("start_time") String start_time,  @RequestParam("end_time") String end_time, 
			@RequestParam("page_size") int page_size, @RequestParam("page_no") int page_no);
	
	
	/***
	 * 
	 * 推广组下的词基础报表数据查询(明细数据不分类型查询)
	 * 
	 * */
	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.rpt.adgroupkeywordbase.get")
	public String getRptAdgroupKeywordBase( @RequestParam("subway_token")String subway_token, @RequestParam("nick") String nick, @RequestParam("campaign_id") long campaign_id, @RequestParam("adgroup_id") long adgroup_id, 
			@RequestParam("source") String source, @RequestParam("search_type") String search_type, @RequestParam("start_time") String start_time, @RequestParam("end_time")  String end_time, 
			@RequestParam("page_size") int page_size, @RequestParam("page_no") int page_no);
	
	/*
	 * 弃用
	 * */
	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.insight.wordsdata.getSSSS")
	public InsightKeywordDataResponse getInsightKeywordData(@RequestHeader("tenantID") long tenantID, @RequestParam("bidword_list") String word, 
			@RequestParam("start_date") String start_date, @RequestParam("end_date")  String end_date);
	
	
	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.insight.wordsdata.get")
	public InsightWordDataResponse getInsightWordData(@RequestHeader("tenantID") long tenantID, @RequestParam("bidword_list") String word, 
			@RequestParam("start_date") String start_date, @RequestParam("end_date")  String end_date);
	
	@Data
	public static class InsightKeywordDataResponse{
		
		@JsonProperty("simba_insight_wordsdata_get_response")
		private InsightKeywordRes res;
	}
	
	@Data
	public static class InsightKeywordRes{
		
		@JsonProperty("word_data_list")
		private WordDataResult result;
	}
	
	@Data
	public static class WordDataResult{
	
		@JsonProperty("insight_word_data_d_t_o")
		private List<InsightWord> dto;
	}
	
	@Data
	public static class InsightWord{
		
        private String bidword;   //": "连衣裙",
        private Long click;    //: 2820610,
        private Long competition; //": 167518,
        private Long cost;   //: 94417753,
        private String coverage; //: "0.22",
        private String cpc;  // ": "35.96",
        private String ctr;  //": "0.4",
        @JsonProperty("directtransaction")
        private Long directTransaction; //": 52357127,
        @JsonProperty("directtransactionshipping")
        private Long directTransactionShipping; //": 5415,
        @JsonProperty("favitemtotal")
        private Long favItemTotal; //": 50323,
        @JsonProperty("favshoptotal")
        private Long favShopTotal; //": 6458,
        @JsonProperty("favtotal")
        private Long favTotal; //": 56386,
        private Long impression; //": 624939453,
        @JsonProperty("indirecttransaction")
        private Long indirectTransaction; //": 20853489,
        @JsonProperty("indirecttransactionshipping")
        private Long indirectTransactionShipping;  //": 1782,
        private String roi; // ": "0.76",
        @JsonProperty("transactionshippingtotal")
        private Long transactionShippingTotal; //": 7119,
        @JsonProperty("transactiontotal")
        private Long transactionTotal; //": 72343545
	
	}
	
	//------------------------------------------------
	
	@Data
	public static class QscoreResponse extends SimbaProxyBaseDto{
		
		@JsonProperty("simba_keywords_qscore_split_get_response")
		private QscoreRes res;
	}
	
	@Data
	public static class QscoreRes{
		
		@JsonProperty("result")
		private QsResult1 result1;
	}
	
	@Data
	public static class QsResult1{
		
		@JsonProperty("result")
		private QsResult result;
	}
	
	@Data
	public static class QsResult{
		
		@JsonProperty("adgroup_id")
		private int adgroupId;
		@JsonProperty("word_score_list")
		private WordScoreList listRes;
	}
	
	@Data
	public static class WordScoreList{
		
		@JsonProperty("wordscorelist")
		private List<Score> list;
	}
	
	@Data
	public static class Score{
		
         private String relescore;
       
         @JsonProperty("campaign_id")
         private long campaignId;
         
         @JsonProperty("adgroup_id")
         private long adgroupId;

         @JsonProperty("wireless_qscore")
         private String wirelessQscore;

         private String qscore;
 
         private String catscore;
        
         private String pscore;

         private String word;
  
         @JsonProperty("keyword_id")
         private long keywordId;

	}
	/***************************************************/
	@Data
	public static class InsightWordDataResponse{
		
		@JsonProperty("simba_insight_wordsdata_get_response")
		private InsightWordRes res;
	}
	
	@Data
	public static class InsightWordRes{
		
		@JsonProperty("word_data_list")
		private WordDataRes result;
	}
	
	@Data
	public static class WordDataRes{
	
		@JsonProperty("insight_word_data_d_t_o")
		private List<InsightWordData> dto;
	}
	
	
}
